<template>
	<div style="margin-top: 30px;margin-bottom: 30px;" @click="dataFiltering()">
		<el-empty :image-size="300" description="没有查询到相关航班信息"
			v-if="this.oneWayFlight.length==0 && this.transferFlight.length==0 && this.whetherToQuery"></el-empty>
		<div align="center" v-else>
			<div style="height: 50px;width: 60%;" v-if="this.radio==6" align="left">
				<div @click="switchDisplay()" :class="this.flightRoundTrip.length==0 ? 'mistakeDisable' : 'DisableTwo'"
					style="height: 50px;border-top-left-radius:13px;border-top-right-radius:13px;display: inline-block;position: relative;z-index: 10;vertical-align:top;">
					<div :class="this.flightRoundTrip.length==0 ? 'mistakeDisableButton' : 'DisableButton'"
						style="border-radius: 50%;height: 35px;width: 35px;display: inline-block;margin-top: 7.5px;margin-left: 20px;"
						align="center">
						<span style="line-height: 35px;font-weight: 900;color: #ffffff;">1</span>
					</div>
					<span style="font-size: 22px;margin-left: 5px;line-height: 50px;">选择去程</span>

					<span style="font-size: 15px;margin-left: 10px;margin-right: 5px;">{{departure}}</span>
					<span style="font-size: 15px;">-</span>
					<span style="font-size: 15px;margin-left: 5px;margin-right: 5px;">{{destination}}</span>
					<span style="font-size: 15px;margin-right: 20px;">{{departureDate[3]}} {{departureDate[1]}}</span>
				</div>
				<div style="height: 100%;border-top-right-radius:10px;display: inline-block;position: relative;right: 10px;vertical-align:top;"
					:class="this.flightRoundTrip.length>=1 ? 'mistakeDisable' : 'Disable'">
					<div :class="this.flightRoundTrip.length>=1 ? 'mistakeDisableButton' : 'DisableButton'"
						style="border-radius: 50%;height: 35px;width: 35px;display: inline-block;margin-top: 7.5px;margin-left: 20px;"
						align="center">
						<span style="line-height: 35px;font-weight: 900;color: #ffffff;">2</span>
					</div>
					<span style="font-size: 22px;margin-left: 5px;line-height: 50px;">选择返程</span>

					<span style="font-size: 15px;margin-left: 10px;margin-right: 5px;">{{destination}}</span>
					<span style="font-size: 15px;">-</span>
					<span style="font-size: 15px;margin-left: 5px;margin-right: 5px;">{{departure}}</span>
					<span style="font-size: 15px;margin-right: 20px;">{{returnDate[3]}} {{returnDate[1]}}</span>
				</div>
			</div>
			<div style="height: 100%;width: 60%;">
				<div style="height: 60px;background-color: #ffffff;">
					<el-row>
						<el-col :span="12" style="text-align: left;padding-left: 10px;">
							<div style="display: inline-block;line-height: 60px;" v-if="this.flightRoundTrip.length==0">
								<span style="font-size: 18px;font-weight: 500;">单程:</span>
								<span
									style="font-size: 25px;font-weight: 900;margin-left: 10px;margin-right: 10px;">{{departure}}</span>
								<span style="font-size: 25px;font-weight: 900;">-</span>
								<span
									style="font-size: 25px;font-weight: 900;margin-left: 10px;margin-right: 10px;">{{destination}}</span>
								<span
									style="font-size: 18px;font-weight: 500;margin-right: 5px;">{{departureDate[3]}}</span>
								<span style="font-size: 18px;font-weight: 500;">{{departureDate[1]}}</span>
							</div>
							<div style="display: inline-block;line-height: 60px;" v-else>
								<span style="font-size: 18px;font-weight: 500;">单程:</span>
								<span
									style="font-size: 25px;font-weight: 900;margin-left: 10px;margin-right: 10px;">{{destination}}</span>
								<span style="font-size: 25px;font-weight: 900;">-</span>
								<span
									style="font-size: 25px;font-weight: 900;margin-left: 10px;margin-right: 10px;">{{departure}}</span>
								<span
									style="font-size: 18px;font-weight: 500;margin-right: 5px;">{{returnDate[3]}}</span>
								<span style="font-size: 18px;font-weight: 500;">{{returnDate[1]}}</span>
							</div>
						</el-col>
						<el-col :span="12" style="text-align: right;">
							<div style="display: inline-block;line-height: 60px;margin-right: 10px;">
								<el-checkbox v-model="transfer" label="中转" border style="margin-right: 10px;">
								</el-checkbox>
								<a href="javascript:;" @click="sort(5)"
									style="text-decoration:none;margin-left: 20px;display: inline-block;margin-right: 20px;">
									<span class="lowPrice">低价优先</span>
								</a>
								<el-dropdown @command="handleCommand">
									<span class="el-dropdown-link" style="color: #606266;">
										更多排序<i class="el-icon-arrow-down el-icon--right"></i>
									</span>
									<el-dropdown-menu slot="dropdown">
										<el-dropdown-item command='0'>起飞早-晚</el-dropdown-item>
										<el-dropdown-item command='1'>起飞晚-早</el-dropdown-item>
										<el-dropdown-item command='2'>耗时短-长</el-dropdown-item>
										<el-dropdown-item command='3'>耗时长-短</el-dropdown-item>
										<el-dropdown-item command='4'>价格高-低</el-dropdown-item>
									</el-dropdown-menu>
								</el-dropdown>
							</div>
						</el-col>
					</el-row>
				</div>
				
				<div style="margin-top: 10px;" v-if="!this.whetherToQuery">
					<el-empty :image-size="100" description="没有找到航班数据"></el-empty>
					</div>

				<div style="margin-top: 10px;" v-if="!transfer && display">
					<div class="information" v-for="item in oneWayFlight">
						<el-row>
							<el-col :span="8">
								<div style="display: table;height: 80px;margin-left: 20px;">
									<div style="display: table-cell;vertical-align: middle;">
										<div>
											<div style="font-size: 18px;font-weight: 900;">
												{{item.flight_name}}
											</div>
											<div style="font-size: 10px;color: #409EFF;">
												{{item.model.model_name}}
											</div>
										</div>
									</div>
								</div>
							</el-col>
							<el-col :span="8" align="center">
								<div style="display: table;height: 80px;">
									<div style="display: table-cell;vertical-align: middle;">
										<div>
											<div style="text-align: right;">
												<span
													style="font-size: 25px;font-weight: 900;">{{item.departure_time}}</span>
											</div>
											<div>
												<span
													style="font-size: 14px;">{{item.setout_information.airport_name}}</span>
											</div>
										</div>
									</div>

									<div style="display: table-cell;vertical-align: middle;">
										<div>
											<div>
												<div
													style="height: 10px;width: 70px;background-color: #D8D8D8;margin-left: 20px;margin-right: 20px;">
												</div>
											</div>
										</div>
									</div>

									<div style="display: table-cell;vertical-align: middle;">
										<div>
											<div style="text-align: left;">
												<span
													style="font-size: 25px;font-weight: 900;">{{item.arrival_time}}</span>
											</div>
											<div>
												<span
													style="font-size: 14px;">{{item.arrive_information.airport_name}}</span>
											</div>
										</div>
									</div>
								</div>
							</el-col>
							<el-col :span="8" style="text-align: right;">
								<div style="display: inline-block;line-height: 80px;margin-right: 20px;">
									<span
										style="font-size: 25px;font-weight: 900;background: -webkit-linear-gradient(315deg,#409EFF 25%,#FFA600);background-clip: text;color: transparent;-webkit-background-clip: text;-webkit-text-fill-color: transparent;">
										￥{{item.flightPrice.economy_price}}
									</span>
								</div>
								<div style="display: inline-block;line-height: 80px;margin-right: 20px;">
									<el-button type="primary" @click='load(item,0)'>订购</el-button>
								</div>
							</el-col>
						</el-row>
					</div>
				</div>


				<div style="height: 40px;margin-top: 10px;text-align: left;"
					v-if='this.transferFlight.length>0 && display'>
					<div
						style="display: inline-block;padding-left: 30px;padding-right: 30px;text-align: center;background-color: #ffffff;height: 100%;">
						<span style="font-size: 20px;font-weight: 900;line-height: 40px;">中转组合</span>
					</div>
					<div
						style="display: inline-block;padding-left: 30px;padding-right: 30px;text-align: center;height: 100%;">
						<a href="javascript:;" style="text-decoration:none;"><span
								style="font-size: 15px;line-height: 40px;color: #409EFF;"
								@click="centerDialogVisible = true">购买须知</span></a>
					</div>
				</div>
				<div class="information" style="position: relative ;" v-if="display" v-for="item in transferFlight">
					<el-row>
						<el-col :span="8">
							<div style="display: table;height: 80px;margin-left: 20px;">
								<div style="display: table-cell;vertical-align: middle;">
									<div>
										<div>
											<span
												style="font-size: 12px;font-weight: 900;">{{item.departureFlight.flight_name}}</span>
											<span
												style="font-size: 10px;color: #409EFF;">({{item.departureFlight.model.model_name}})</span>
										</div>
										<div>
											<span
												style="font-size: 12px;font-weight: 900;">{{item.destinationFlight.flight_name}}</span>
											<span
												style="font-size: 10px;color: #409EFF;">({{item.destinationFlight.model.model_name}})</span>
										</div>
									</div>
								</div>
							</div>
						</el-col>
						<el-col :span="8" align="center">

							<div style="display: table;height: 80px;">
								<div style="display: table-cell;vertical-align: middle;">
									<div>
										<div style="text-align: right;">
											<span
												style="font-size: 25px;font-weight: 900;">{{item.departureFlight.departure_time}}</span>
										</div>
										<div>
											<span
												style="font-size: 14px;">{{item.departureFlight.setout_information.airport_name}}</span>
										</div>
									</div>
								</div>

								<div style="display: table-cell;vertical-align: middle;" class="ag">
									<div>
										<div style="margin-left: 20px;margin-right: 20px;">
											<span
												style="font-size: 10px;color: #A0A0A0;">中转{{item.timeDifference.hours}}时{{item.timeDifference.minutes}}分</span>
										</div>
										<div>
											<div style="height: 10px;width: 70px;background-color: #D8D8D8;"></div>
										</div>
										<div>
											<span
												style="font-size: 10px;color: #A0A0A0;margin-left: 20px;margin-right: 20px;"><span>转</span><span
													style="color: #000000;">{{item.departureFlight.destinationCity.city_name}}{{item.timeDifference.hours}}h{{item.timeDifference.minutes}}m</span></span>
										</div>
									</div>
									<div id="details"
										style="position: absolute;z-index: 999;width: 60%;background-color: #ffffff;box-shadow: 0px 0px 5px rgb(0, 0, 0, 0.2);display: none;bottom: 90%;right: 20%;">
										<div style="width: 90%;height: 100%;">
											<div align="left">
												<div style="margin-top: 10px;margin-bottom: 20px;">
													<span
														style="font-size: 20px;font-weight: 900;margin-right: 5px;">{{departure}}</span>
													<span
														style="font-size: 20px;font-weight: 900;color: #D8D8D8;">-</span>
													<span
														style="font-size: 20px;font-weight: 900;margin-left: 5px;margin-right: 5px;">{{destination}}</span>
													<span style="font-size: 17px;font-weight: 600;color: #D8D8D8;">
														总时长{{item.timeDifferenceSum.hours}}时{{item.timeDifferenceSum.minutes}}分
													</span>
												</div>
												<div style="margin-bottom: 20px;">
													<span style="font-size: 15px;">航班号: <span
															style="color: #409EFF;">{{item.departureFlight.flight_name}}</span></span>
													<span style="font-size: 15px;margin-left: 15px;">航班型号: <span
															style="color: #409EFF;">{{item.departureFlight.model.model_name}}</span></span>
												</div>
												<div style="margin-top: 10px;">
													<div
														style="width: 10px;height: 10px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.departureFlight.departureTime.departure}}</span>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.departureFlight.departure_time}}</span>
													<span
														style="font-size: 15px;font-weight: 500;">{{item.departureFlight.setout_information.airport_name}}</span>
												</div>
												<div style="margin-top: 5px;">
													<div
														style="width: 10px;height: 90px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>
													<div
														style="height: 90px;display: inline-block;color: #969595;vertical-align:top; ">
														<span style="line-height: 90px;font-size: 14px;">飞行
															{{item.departureFlight.timeOfFlight.hours}}小时{{item.departureFlight.timeOfFlight.minutes}}分</span><!-- 飞行{{item.departureFlight.timeOfFlight.hours}}时{{item.departureFlight.timeOfFlight.minutes}}分 -->
													</div>
												</div>
												<div>
													<div
														style="width: 10px;height: 10px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.departureFlight.departureTime.destination}}</span>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.departureFlight.arrival_time}}</span>
													<span
														style="font-size: 15px;font-weight: 500;">{{item.departureFlight.arrive_information.airport_name}}</span>
												</div>
												<hr
													style="margin-top: 20px;background-color: rgb(216, 216, 216);height: 1px;border:none">
												<div style="font-size: 12px;margin-top: 5px;">
													<div
														style="width: 5px;height: 5px;background-color: #ffaa00;display: inline-block;margin-right: 5px;">
													</div>
													{{item.departureFlight.destinationCity.city_name}} 中转 停留
													</span>{{item.timeDifference.hours}}小时{{item.timeDifference.minutes}}分</span>
												</div>
												<hr
													style="margin-top: 5px;background-color: rgb(216, 216, 216);height: 1px;border:none">

												<div style="margin-top: 20px;margin-bottom: 20px;">
													<span style="font-size: 15px;">航班号: <span
															style="color: #409EFF;">{{item.destinationFlight.flight_name}}</span></span>
													<span style="font-size: 15px;margin-left: 15px;">航班型号: <span
															style="color: #409EFF;">{{item.destinationFlight.model.model_name}}</span></span>
												</div>
												<div style="margin-top: 10px;">
													<div
														style="width: 10px;height: 10px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.destinationFlight.departureTime.departure}}</span>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.destinationFlight.departure_time}}</span>
													<span
														style="font-size: 15px;font-weight: 500;">{{item.destinationFlight.setout_information.airport_name}}</span>
												</div>
												<div style="margin-top: 5px;">
													<div
														style="width: 10px;height: 90px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>
													<div
														style="height: 90px;display: inline-block;color: #969595;vertical-align:top; ">
														<span style="line-height: 90px;font-size: 14px;">飞行
															{{item.destinationFlight.timeOfFlight.hours}}小时{{item.destinationFlight.timeOfFlight.minutes}}分</span><!-- 飞行{{item.departureFlight.timeOfFlight.hours}}时{{item.departureFlight.timeOfFlight.minutes}}分 -->
													</div>
												</div>
												<div style="margin-bottom: 10px;">
													<div
														style="width: 10px;height: 10px;background-color: #D8D8D8;display: inline-block;margin-right: 10px;">
													</div>

													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.destinationFlight.departureTime.destination}}</span>
													<span
														style="font-size: 15px;font-weight: 500;margin-right: 5px;">{{item.destinationFlight.arrival_time}}</span>
													<span
														style="font-size: 15px;font-weight: 500;">{{item.destinationFlight.arrive_information.airport_name}}</span>
												</div>
											</div>
										</div>
									</div>
								</div>

								<div style="display: table-cell;vertical-align: middle;">
									<div>
										<div style="text-align: left;">
											<span
												style="font-size: 25px;font-weight: 900;">{{item.destinationFlight.arrival_time}}
												<span
													style="font-size: 13px;color: #409EFF;position: absolute;margin-left: 5px;font-weight: 900;"
													v-if="item.spanTiem.day>0">+{{item.spanTiem.day}}天</span>
											</span>
										</div>
										<div>
											<span
												style="font-size: 14px;">{{item.destinationFlight.arrive_information.airport_name}}</span>
										</div>
									</div>
								</div>
							</div>

						</el-col>
						<el-col :span="8" style="text-align: right;">
							<div style="display: inline-block;line-height: 80px;margin-right: 20px;">
								<span
									style="font-size: 25px;font-weight: 900;background: -webkit-linear-gradient(315deg,#409EFF 25%,#FFA600);background-clip: text;color: transparent;-webkit-background-clip: text;-webkit-text-fill-color: transparent;">
									￥{{item.destinationFlight.flightPrice.economy_price+item.departureFlight.flightPrice.economy_price}}
								</span>
							</div>
							<div style="display: inline-block;line-height: 80px;margin-right: 20px;">
								<el-button type="primary" @click='load(item,1)'>订购</el-button>
							</div>
						</el-col>
					</el-row>
				</div>
				<el-skeleton :rows="10" animated v-if="!display" style="margin-top: 10px;text-align: left;" />

			</div>
		</div>
		<el-dialog title="中转须知" :visible.sync="centerDialogVisible" width="25%" :show-close="false" center>
			<div>
				<p style="color: red;margin-bottom: 10px;">1.所有中转航班最大跨越限度为一天</p>
				<p style="margin-bottom: 10px;">2.每段航班均需缴纳机建和燃油税</p>
				<p style="margin-bottom: 10px;">3.因天气及突发事件等原因，可能影响乘客登机或乘车。请确认换乘距离和中转时间，以便确定合适的航班、车次</p>
				<p style="margin-bottom: 10px;">4.如发生航班延误，您有权索要延误证明以便于与我司协商处理</p>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="centerDialogVisible = false">我已知晓</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import axios from 'axios';

	export default {
		created() {
			this.oneWay();
		},
		watch: {

		},
		data() {
			return {
				centerDialogVisible: false,
				count: 10,
				transfer: false,
				take: false,
				oneWayFlight: [],
				transferFlight: [],
				departure: "",
				destination: "",
				departureDate: "",
				returnDate: "",
				back: -1,
				display: true,
				radio: 3,
				flightRoundTrip: [],
				oneWayFlightTwo: [],
				transferFlightTwo: [],
				whetherToQuery: true
			}
		},
		methods: {
			switchDisplay() {
				if (this.radio == 6) {
					if (this.flightRoundTrip.length >= 1) {
						this.flightRoundTrip = [];
						//切换数据
						var oneWayFlight = JSON.parse(JSON.stringify(this.oneWayFlightTwo));
						var transferFlight = JSON.parse(JSON.stringify(this.transferFlightTwo));

						this.oneWayFlightTwo = JSON.parse(JSON.stringify(this.oneWayFlight));
						this.transferFlightTwo = JSON.parse(JSON.stringify(this.transferFlight));

						this.oneWayFlight = oneWayFlight;
						this.transferFlight = transferFlight;
						
						this.whetherToQuery=true;
					}
				}
			},
			tomorrow(date) {
				var time = new Date(date);
				time.setTime(time.getTime() + 1 * 24 * 60 * 60 * 1000);
				var M = time.getMonth();
				M = (M + 1) < 10 ? '0' + (M + 1) : (M + 1);
				var d = time.getDate();
				d = d < 10 ? '0' + d : d;
				return M + "-" + d;
			},
			async load(data, is) {
				if (this.radio == 6) {
					if (this.flightRoundTrip.length == 0) {
						var flightRoundTrip=[];
						if(is==1){
							flightRoundTrip=new Array(this.flightRoundTrip.length+2);
							flightRoundTrip[0] = this.dataSupplementation(data.departureFlight);
							flightRoundTrip[1]=this.dataSupplementation(data.destinationFlight);
							flightRoundTrip[0].number=0;
							flightRoundTrip[1].number=1;
							flightRoundTrip[0].transfer=1;
							flightRoundTrip[1].transfer=1;
						}else{
							flightRoundTrip=new Array(this.flightRoundTrip.length+1);
							flightRoundTrip[0]=this.dataSupplementation(data);
							flightRoundTrip[0].number=0;
							flightRoundTrip[0].transfer=0;
						}
						
						this.flightRoundTrip = flightRoundTrip;
						this.display = false;
						var res = this.oneWayTwo();
						await res.then((data) => {
							this.dataExtraction(data);
						});
						res = this.transferFunTwo();
						await res.then((data) => {
							this.dataExtractionTwo(data);
						});
						
						//切换数据
						var oneWayFlight = JSON.parse(JSON.stringify(this.oneWayFlight));
						var transferFlight = JSON.parse(JSON.stringify(this.transferFlight));

						this.oneWayFlight = JSON.parse(JSON.stringify(this.oneWayFlightTwo));
						this.transferFlight = JSON.parse(JSON.stringify(this.transferFlightTwo));
						
						if(this.oneWayFlight.length<=0 && this.transferFlight.length<=0){
							this.whetherToQuery = false;
						}
						this.oneWayFlightTwo = oneWayFlight;
						this.transferFlightTwo = transferFlight;
						this.display = true;
					} else {
						
						if (sessionStorage.getItem("eleToken") == null) {
							if(!this.$parent.loginOpen()){
								this.$message({
									message: '完成登录才能进行下一步',
									type: 'warning'
								});
							}
							return;
						}
						
						var flightRoundTrip=[];
						if(is==1){
							flightRoundTrip=new Array(this.flightRoundTrip.length+2);
						}else{
							flightRoundTrip=new Array(this.flightRoundTrip.length+1);
						}

						for(var i=0;i<this.flightRoundTrip.length;i++){
							flightRoundTrip[i]=this.flightRoundTrip[i];
						}
						if(is==1){
							flightRoundTrip[this.flightRoundTrip.length] = this.dataSupplementation(data.departureFlight);
							flightRoundTrip[this.flightRoundTrip.length+1]=this.dataSupplementation(data.destinationFlight);
							flightRoundTrip[this.flightRoundTrip.length].number=this.flightRoundTrip.length;
							flightRoundTrip[this.flightRoundTrip.length+1].number=this.flightRoundTrip.length+1;
							flightRoundTrip[this.flightRoundTrip.length].transfer=1;
							flightRoundTrip[this.flightRoundTrip.length+1].transfer=1;
						}else{
							flightRoundTrip[this.flightRoundTrip.length]=this.dataSupplementation(data);
							flightRoundTrip[this.flightRoundTrip.length].number=this.flightRoundTrip.length;
							flightRoundTrip[this.flightRoundTrip.length].transfer=0;
						}
						
						sessionStorage.setItem("flightIn", JSON.stringify(flightRoundTrip));
						location.href = "/FlightInformation";
						
					}
				} else {
					if (sessionStorage.getItem("eleToken") == null) {
						if(!this.$parent.loginOpen()){
							this.$message({
								message: '完成登录才能进行下一步',
								type: 'warning'
							});
						}
						return;
					}
					
					var flightInformation=[];
					
					if(is==1){
						var one = this.dataSupplementation(data.departureFlight);
						var two = this.dataSupplementation(data.destinationFlight);
						one.number=0;
						two.number=1;
						one.transfer=1;
						two.transfer=1;
						flightInformation = [
							one,
							two
						];
					}else{
						var one = this.dataSupplementation(data);
						one.number=0;
						one.transfer=0;
						flightInformation = [
							one
						];
					}
					sessionStorage.setItem("flightIn", JSON.stringify(flightInformation));
					location.href = "/FlightInformation";
				}
			},
			dataSupplementation(data){
				data.accurateTime=this.dateNow(new Date(data.departureTime.departure));
				var cabin=new Set();
				var price=new Set();
				if(data.flightPrice.economy_price>0){
					cabin.add("经济舱");
					price.add(data.flightPrice.economy_price);
				}
				if(data.flightPrice.commercial_affairs_price>0){
					cabin.add("商务舱");
					price.add(data.flightPrice.commercial_affairs_price);
				}
				if(data.flightPrice.first_class_price>0){
					cabin.add("头等舱");
					price.add(data.flightPrice.first_class_price);
				}
				data.cabin=[...cabin];
				data.price=[...price];
				data.priceDifferentiation=0;
				return data;
			},
			dateNow(date) {
				var time = date;
				var Y = time.getFullYear();
				var M = time.getMonth();
				M = (M + 1) < 10 ? '0' + (M + 1) : (M + 1);
				var d = time.getDate();
				d = d < 10 ? '0' + d : d;
				var week = new Array("日", "一", "二", "三", "四", "五", "六");
				return new Array(Y + "-" + M + "-" + d, "周" + week[time.getDay()], time, M + "-" + d);
			},
			dataExtraction(res) {
				if (res.data.code === 200) {
					if (res.data.data !== undefined) {
						this.oneWayFlightTwo = res.data.data;
						for (var i = 0; i < res.data.data.length; i++) {
							res.data.data[i].departure_time = this.timeInterception(res.data
								.data[i]
								.departure_time);
							res.data.data[i].arrival_time = this.timeInterception(res.data
								.data[i]
								.arrival_time);
						}
					} else {
						this.oneWayFlightTwo = [];
					}
				} else {
					this.$message({
						dangerouslyUseHTMLString: true,
						message: '<strong>' + res.data.msg + '</strong>',
						type: 'error'
					});
				}
			},
			dataExtractionTwo(res) {
				if (res.data.code === 200) {
					if (res.data.data !== undefined) {
						if (res.data.data.length != 0) {
							this.transferFlightTwo = res.data.data;
							for (var i = 0; i < res.data.data.length; i++) {

								var departureFlightArrival_time = res.data.data[i].departureFlight.arrival_time.split(":");
								res.data.data[i].departureFlight.arrival_time = departureFlightArrival_time[0] + ":" +
									departureFlightArrival_time[1];
								var departureFlightDeparture_time = res.data.data[i].departureFlight.departure_time.split(
									":");
								res.data.data[i].departureFlight.departure_time = departureFlightDeparture_time[0] + ":" +
									departureFlightDeparture_time[1];

								departureFlightArrival_time = res.data.data[i].destinationFlight.arrival_time.split(":");
								res.data.data[i].destinationFlight.arrival_time = departureFlightArrival_time[0] + ":" +
									departureFlightArrival_time[1];
								departureFlightDeparture_time = res.data.data[i].destinationFlight.departure_time.split(
									":");
								res.data.data[i].destinationFlight.departure_time = departureFlightDeparture_time[0] +
									":" + departureFlightDeparture_time[1];
							}
						} else {
							this.transferFlightTwo = [];
						}
					} else {
						this.transferFlightTwo = [];
					}
				} else {
					this.$message({
						dangerouslyUseHTMLString: true,
						message: '<strong>' + res.data.msg + '</strong>',
						type: 'error'
					});
				}
			},
			timeInterception(time) {
				return time.slice(0, -3);
			},
			oneWayTwo() {
				var formData = new FormData();
				formData.append('departure', this.destination);
				formData.append('destination', this.departure);
				formData.append('departureTime', this.returnDate[0]);

				return new Promise((resolve, reject) => {
					axios.post("api/FlightAction/oneWayQuery", formData)
						.then((res) => {
							resolve(res);
						});
				});
			},
			transferFunTwo() {
				var formData = new FormData();
				formData.append('departure', this.destination);
				formData.append('destination', this.departure);
				formData.append('departureTime', this.returnDate[0]);

				return new Promise((resolve, reject) => {
					axios.post("api/FlightAction/transferQuery", formData)
						.then((res) => {
							resolve(res);
						});
				});
			},
			oneWay() {
				this.whetherToQuery = true;
				this.flightRoundTrip = [];
				this.oneWayFlight = [];
				this.transferFlight = [];
				this.radio = sessionStorage.getItem("radio");
				this.departure = sessionStorage.getItem("cityName");
				this.destination = sessionStorage.getItem("cityNameTwo");
				this.departureDate = sessionStorage.getItem("departureDate").split(",");
				this.returnDate = sessionStorage.getItem("returnDate").split(",");

				var formData = new FormData();
				formData.append('departure', this.departure);
				formData.append('destination', this.destination);
				formData.append('departureTime', this.departureDate[0]);
				axios.post("api/FlightAction/oneWayQuery", formData)
					.then((res) => {
						if (res.data.code === 200) {
							if (res.data.data !== undefined) {
								this.oneWayFlight = res.data.data;
								for (var i = 0; i < res.data.data.length; i++) {
									res.data.data[i].departure_time = this.timeInterception(res.data.data[i]
										.departure_time);
									res.data.data[i].arrival_time = this.timeInterception(res.data.data[i]
										.arrival_time);
								}
							} else {
								this.oneWayFlight = [];
							}
							this.transferFun();
						} else {
							this.$message({
								dangerouslyUseHTMLString: true,
								message: '<strong>' + res.data.msg + '</strong>',
								type: 'error'
							});
						}
					});
			},
			dataFiltering() {
				// console.log(this.oneWayFlightTwo)
			},
			transferFun() {
				var formData = new FormData();
				formData.append('departure', this.departure);
				formData.append('destination', this.destination);
				formData.append('departureTime', this.departureDate[0]);
				axios.post("api/FlightAction/transferQuery", formData)
					.then((res) => {
						if (res.data.code === 200) {
							if (res.data.data !== undefined) {
								if (res.data.data.length != 0) {
									this.transferFlight = res.data.data;
									for (var i = 0; i < res.data.data.length; i++) {

										var departureFlightArrival_time = res.data.data[i].departureFlight.arrival_time
											.split(":");
										res.data.data[i].departureFlight.arrival_time = departureFlightArrival_time[
											0] + ":" + departureFlightArrival_time[1];
										var departureFlightDeparture_time = res.data.data[i].departureFlight
											.departure_time.split(":");
										res.data.data[i].departureFlight.departure_time =
											departureFlightDeparture_time[0] + ":" + departureFlightDeparture_time[1];

										departureFlightArrival_time = res.data.data[i].destinationFlight.arrival_time
											.split(":");
										res.data.data[i].destinationFlight.arrival_time = departureFlightArrival_time[
											0] + ":" + departureFlightArrival_time[1];
										departureFlightDeparture_time = res.data.data[i].destinationFlight
											.departure_time.split(":");
										res.data.data[i].destinationFlight.departure_time =
											departureFlightDeparture_time[0] + ":" + departureFlightDeparture_time[1];
									}
								} else {
									this.transferFlight = [];
								}
							} else {
								this.transferFlight = [];
							}
						} else {
							this.$message({
								dangerouslyUseHTMLString: true,
								message: '<strong>' + res.data.msg + '</strong>',
								type: 'error'
							});
						}
					});
			},
			handleCommand(command) {
				this.sort(command);
			},
			time_to_sec(time) {
				if (time !== null) {
					var s = "";
					var hour = time.getHours();
					var min = time.getMinutes();
					var sec = time.getSeconds();
					s = Number(hour * 3600) + Number(min * 60) + Number(sec);
					return s;
				}
			},
			compareTime(time1, time2) {
				if (this.time_to_sec(time2) - this.time_to_sec(time1) > 0) {
					return true;
				}
				return false;
			},
			sort(serialNumber) {
				if (this.back == serialNumber) {
					return;
				}
				var oneWayFlight = this.oneWayFlight;
				var transferFlight = this.transferFlight;
				if (serialNumber == 0) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {
							var time_one = new Date();
							time_one.setHours(oneWayFlight[j].departure_time.split(":")[0]);
							time_one.setMinutes(oneWayFlight[j].departure_time.split(":")[1]);
							var time_two = new Date();
							time_two.setHours(oneWayFlight[j + 1].departure_time.split(":")[0]);
							time_two.setMinutes(oneWayFlight[j + 1].departure_time.split(":")[1]);
							if (this.compareTime(time_two, time_one)) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {
							var time_one = new Date();
							time_one.setHours(transferFlight[j].departureFlight.departure_time.split(":")[0]);
							time_one.setMinutes(transferFlight[j].departureFlight.departure_time.split(":")[1]);
							var time_two = new Date();
							time_two.setHours(transferFlight[j + 1].departureFlight.departure_time.split(":")[0]);
							time_two.setMinutes(transferFlight[j + 1].departureFlight.departure_time.split(":")[1]);
							if (this.compareTime(time_two, time_one)) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 0;
				} else if (serialNumber == 1) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {
							var time_one = new Date();
							time_one.setHours(oneWayFlight[j].departure_time.split(":")[0]);
							time_one.setMinutes(oneWayFlight[j].departure_time.split(":")[1]);
							var time_two = new Date();
							time_two.setHours(oneWayFlight[j + 1].departure_time.split(":")[0]);
							time_two.setMinutes(oneWayFlight[j + 1].departure_time.split(":")[1]);
							if (this.compareTime(time_one, time_two)) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {
							var time_one = new Date();
							time_one.setHours(transferFlight[j].departureFlight.departure_time.split(":")[0]);
							time_one.setMinutes(transferFlight[j].departureFlight.departure_time.split(":")[1]);
							var time_two = new Date();
							time_two.setHours(transferFlight[j + 1].departureFlight.departure_time.split(":")[0]);
							time_two.setMinutes(transferFlight[j + 1].departureFlight.departure_time.split(":")[1]);
							if (this.compareTime(time_one, time_two)) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 1;
				} else if (serialNumber == 2) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {

							var time_one = new Date();
							time_one.setHours(oneWayFlight[j].departure_time.split(":")[0]);
							time_one.setMinutes(oneWayFlight[j].departure_time.split(":")[1]);

							var time_one_two = new Date();
							time_one_two.setHours(oneWayFlight[j].arrival_time.split(":")[0]);
							time_one_two.setMinutes(oneWayFlight[j].arrival_time.split(":")[1]);
							var timeCount = this.time_to_sec(time_one_two) - this.time_to_sec(time_one);

							var time_two = new Date();
							time_two.setHours(oneWayFlight[j + 1].departure_time.split(":")[0]);
							time_two.setMinutes(oneWayFlight[j + 1].departure_time.split(":")[1]);

							var time_two_two = new Date();
							time_two_two.setHours(oneWayFlight[j + 1].arrival_time.split(":")[0]);
							time_two_two.setMinutes(oneWayFlight[j + 1].arrival_time.split(":")[1]);
							var timeCountTwo = this.time_to_sec(time_two_two) - this.time_to_sec(time_two);

							if (timeCount > timeCountTwo) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {

							var timeCount = transferFlight[j].timeDifferenceSum.hours * 3600 + transferFlight[j]
								.timeDifferenceSum.minutes * 60;
							var timeCountTwo = transferFlight[j + 1].timeDifferenceSum.hours * 3600 + transferFlight[j + 1]
								.timeDifferenceSum.minutes * 60;

							if (timeCount > timeCountTwo) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 2;
				} else if (serialNumber == 3) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {

							var time_one = new Date();
							time_one.setHours(oneWayFlight[j].departure_time.split(":")[0]);
							time_one.setMinutes(oneWayFlight[j].departure_time.split(":")[1]);

							var time_one_two = new Date();
							time_one_two.setHours(oneWayFlight[j].arrival_time.split(":")[0]);
							time_one_two.setMinutes(oneWayFlight[j].arrival_time.split(":")[1]);
							var timeCount = this.time_to_sec(time_one_two) - this.time_to_sec(time_one);

							var time_two = new Date();
							time_two.setHours(oneWayFlight[j + 1].departure_time.split(":")[0]);
							time_two.setMinutes(oneWayFlight[j + 1].departure_time.split(":")[1]);

							var time_two_two = new Date();
							time_two_two.setHours(oneWayFlight[j + 1].arrival_time.split(":")[0]);
							time_two_two.setMinutes(oneWayFlight[j + 1].arrival_time.split(":")[1]);
							var timeCountTwo = this.time_to_sec(time_two_two) - this.time_to_sec(time_two);

							if (timeCount < timeCountTwo) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {

							var timeCount = transferFlight[j].timeDifferenceSum.hours * 3600 + transferFlight[j]
								.timeDifferenceSum.minutes * 60;
							var timeCountTwo = transferFlight[j + 1].timeDifferenceSum.hours * 3600 + transferFlight[j + 1]
								.timeDifferenceSum.minutes * 60;

							if (timeCount < timeCountTwo) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 3;
				} else if (serialNumber == 4) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {

							var price = oneWayFlight[j].flightPrice.economy_price;
							var priceTwo = oneWayFlight[j + 1].flightPrice.economy_price;

							if (price < priceTwo) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {

							var price = transferFlight[j].departureFlight.flightPrice.economy_price + transferFlight[j]
								.destinationFlight.flightPrice.economy_price;
							var priceTwo = transferFlight[j + 1].departureFlight.flightPrice.economy_price +
								transferFlight[j + 1].destinationFlight.flightPrice.economy_price;

							if (price < priceTwo) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 4;
				} else if (serialNumber == 5) {
					this.display = false;
					for (var i = 0; i < oneWayFlight.length; i++) {
						for (var j = 0; j < oneWayFlight.length - 1 - i; j++) {

							var price = oneWayFlight[j].flightPrice.economy_price;
							var priceTwo = oneWayFlight[j + 1].flightPrice.economy_price;

							if (price > priceTwo) {
								var temp = oneWayFlight[j]
								oneWayFlight[j] = oneWayFlight[j + 1]
								oneWayFlight[j + 1] = temp
							}
						}
					}

					for (var i = 0; i < transferFlight.length; i++) {
						for (var j = 0; j < transferFlight.length - 1 - i; j++) {

							var price = transferFlight[j].departureFlight.flightPrice.economy_price + transferFlight[j]
								.destinationFlight.flightPrice.economy_price;
							var priceTwo = transferFlight[j + 1].departureFlight.flightPrice.economy_price +
								transferFlight[j + 1].destinationFlight.flightPrice.economy_price;

							if (price > priceTwo) {
								var temp = transferFlight[j]
								transferFlight[j] = transferFlight[j + 1]
								transferFlight[j + 1] = temp
							}
						}
					}
					this.display = true;
					this.back = 5;
				}
			}

		}
	}
</script>

<style>
	.Disable {
		cursor: not-allowed;
		cursor: no-drop;
		background-color: #dadada;
	}

	.DisableTwo {
		background-color: #dadada;
	}

	.DisableButton {
		background-color: #b1b8bd;
	}

	.mistakeDisableButton {
		background-color: #409EFF;
	}

	.mistakeDisable {
		background-color: #FFFFFF;
	}

	.ag:hover #details {
		display: block !important;
	}

	.information {
		height: 80px;
		background-color: #ffffff;
		text-align: left;
		margin-bottom: 5px;
	}

	.information:hover {
		box-shadow: 0px 0px 5px rgb(0, 0, 0, 0.2);
	}

	.lowPrice {
		font-size: 15px;
		color: #409EFF;
		font-weight: 700;
		padding: 10px;
	}

	.lowPrice:hover {
		color: #00ABFF;
		background-color: rgb(0, 171, 255, 0.1);
	}
</style>